package net.dfrz.oa.pojo;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 * 角色类
 * @author vovh
 * 
 */
@Entity
@Table(name="t_role")
public class Role implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;//角色名
	private String desc;//角色描述
	private String number;//角色编号
	private Set<Autority> autorities= new HashSet<Autority>(); //n-n 中间表 roleId autorityId
	@GeneratedValue
	@Column(name="id")
	@Id
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	//1. name 指向中间表的名字
	//2. joinColumns 映射当前类所在的表在中间表中的外键
	//2.1 name 指定外键列的列名
	//2.2 referencedColumnName 指定外键列关联当前表的哪一列
	//3. inverseJoinColumns 映射关联的类所在中间表的外键
	@JoinTable(name="t_role_autority",
			joinColumns={@JoinColumn(name="roleId",referencedColumnName="id")},
			inverseJoinColumns={@JoinColumn(name="autorityId",referencedColumnName="id")})
	@ManyToMany(fetch=FetchType.EAGER)
	public Set<Autority> getAutorities() {
		return autorities;
	}
	public void setAutorities(Set<Autority> autorities) {
		this.autorities = autorities;
	}

}
